{% extends base %}

{% block head %}
    <script type="text/javascript" src="/static/lib/csv.js/csv.js"></script>
    <script type="text/javascript" src="/static/lib/marked/marked.js"></script>
    <script type="text/javascript" src="/static/js/marked-ext.js"></script>

    {% include note/component/view_css.html %}

{% end %}


{% block body %}
    {% init file_type       = "md" %}
    {% init pathlist        = [] %}
    {% init file            = None %}
    {% init show_notice     = False %}
    {% init show_search_div = True %}
    {% init show_add_file   = False %}
    {% init show_add_group  = False %}
    {% init show_path_list  = True %}
    {% init show_pagination = False %}
    {% init show_comment    = True %}
    {% init error           = "" %}

    {% if file != None %}
        {% set globals()['file_type'] = file.type %}
        {% set globals()['file_id'] = file.id %}
    {% end %}

    {# 收藏一下这个符号 › #}
    <div class="col-md-12 card">
        {% comment 如果有新类型的文件，继续增加file_type即可，后台实现不用变更 %}
        {% if file_type == "group" %}
            {% include note/editor/note_list.html %}
        {% elif file_type in ("md", "text", "log", "plan") %}
            {% include note/editor/markdown.html %}
        {% elif file_type == "csv" %}
            {% include note/editor/table.html %}
        {% elif file_type == "gallery" %}
            {% include note/editor/gallery.html %}
        {% elif file_type == "list" %}
            {% include note/editor/list.html %}
        {% else %}
            {% include note/editor/post.html %}
        {% end %}
    </div>

    {# 评论功能 #}
    {% if file_type != "group" and show_comment %}
        {% include note/page/comment.html %}
    {% end %}

    {# 分页 #}
    {% if show_pagination and "page" in globals() %}
        <div class="card">
            {% include mod_pagenation.html %}
        </div>
    {% end %}

<script type="text/javascript">
function rename(id, oldName) {
    xnote.prompt("新名称", oldName, function (newName) {
        console.log(newName);
        if (newName != "" && newName != null) {
            $.post("/note/rename", {id:id, name:newName}, function (resp) {
                var code = resp.code;
                if (code != "success") {
                    alert(resp.message);
                } else {
                    // $("#file-"+id).text(newName);
                    window.location.reload();
                }
            })
        }
    });
}

function remove(id, name, parentId) {
    var confirmed = xnote.confirm("确定删除'" + name + "'?", function (confirmed) {
        if (confirmed) {
            $.post("/note/remove", {id:id}, function (resp) {
                var code = resp.code;
                if (code != "success") {
                    alert(resp.message);
                } else {
                    if (parentId) {
                        window.location.href = "/note/" + parentId;
                    } else {
                        window.location.href = "/";
                    }
                }
            })
        }
    });
}

$(function () {
    window.adjustTable();
})
</script>

{% end %}

{% block aside %}
    {% include note/component/mod_aside.html %}
{% end %}
